<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            position: relative;
            width: 100vw;
            height: 100vh;
        }
        .box{
            display: flex;
            justify-content: center;
            align-items: center;
            position: absolute;
            width: 400px;
            height: 400px;
            background: skyblue;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div id="box" class="box">
        按住拖动box
    </div>
    <script>
        const box=document.getElementById('box');
        let isDown=false;
        let mouse={};
        box.onmousedown=(e)=>{
            isDown=true;
            box.style.cursor='move';
            mouse={
                startX:e.clientX,
                startY:e.clientY,
                offsetLeft:box.offsetLeft,
                offsetTop:box.offsetTop,

            }
        }
        box.onmousemove=(e)=>{
            if(!isDown)
                return;
            let offsetLeft=mouse.offsetLeft+e.clientX-mouse.startX;
            
        }
    </script>
</body>
</html>